package com.nantian.logic.controller.campusRelated;

import com.cuit.springboot.gdao.university.UnivCampusMapper;
import com.cuit.springboot.gentry.university.UnivCampus;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nantian.logic.utils.UniversalResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping(value="/univCampus")
public class UnivCampusController {
    @Autowired
    UnivCampusMapper univCampusMapper;
    @PostMapping(value = "/getCampNumByUnivId")
    public UniversalResult select(@RequestBody Map map) {

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getCampTotalNum(Integer.parseInt(map.get("univId").toString())));
    }

    @PostMapping(value = "/getCampDetailByUnivID")
    public UniversalResult selectCampByUnivID(@RequestBody Map map) {
        if(map.get("univId").toString() != null && !map.get("univId").toString().equals("")){
            PageHelper.startPage(Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
            PageInfo<UnivCampus> page = new PageInfo<>(univCampusMapper.getCampDetailByUnivID(map));
            return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", page);
        }
        return new UniversalResult<>(UniversalResult.SUCCESS, "查询失败", "条件不匹配");

//        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getCampDetailByUnivID(Integer.parseInt(map.get("univId").toString())));
    }

    @PostMapping(value = "/getCampDetailByCampId")
    public UniversalResult selectCampByCampID(@RequestBody Map map) {

//        PageHelper.startPage(map.get("pageNo"), map.get("pageSize"));
//        PageInfo<Activity> page = new PageInfo<>(activityMapper.selectAll());

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getCampDetailByCampId(Integer.parseInt(map.get("campId").toString())));
    }

    @PostMapping(value = "/getStudentByCampID")
    public UniversalResult selectStudentByCampID(@RequestBody Map map) {

//        PageHelper.startPage(map.get("pageNo"), map.get("pageSize"));
//        PageInfo<Activity> page = new PageInfo<>(activityMapper.selectAll());

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getStudentByCampID(Integer.parseInt(map.get("campId").toString())));
    }

    @PostMapping(value = "/getStudentByMemID")
    public UniversalResult selectStudentByMemID(@RequestBody Map map) {


        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getMemberDetailByMemId(Integer.parseInt(map.get("memId").toString())));
    }

    @PostMapping(value = "/getActByMemID")
    public UniversalResult selectActivityByMemID(@RequestBody Map map) {

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getActByMemID(Integer.parseInt(map.get("memId").toString())));
    }

    @PostMapping(value = "/getActByCampID")
    public UniversalResult selectActivityByCampID(@RequestBody Map map) {

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getActByCampID(Integer.parseInt(map.get("campId").toString())));
    }

    @PostMapping(value = "/getOtherCampByCampID")
    public UniversalResult selectOtherCampByCampID(@RequestBody Map map) {

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getOtherCampByCampID(Integer.parseInt(map.get("campId").toString())));
    }

    @PostMapping(value = "/getUnivListByMults")
    public UniversalResult selectUnivListByMults(@RequestBody Map map) {
        PageHelper.startPage(Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
        PageInfo<UnivCampus> page = new PageInfo<>(univCampusMapper.getUnivListByMults(map));
        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", page);
//        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getUnivListByMults(Integer.parseInt(map.get("provId").toString()),Integer.parseInt(map.get("cityId").toString()),map.get("univName").toString()));
//        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getUnivListByMults(map));
    }

    @PostMapping(value = "/getLastActByCampID")
    public UniversalResult selectLastActByCampID(@RequestBody Map map) {

        return new UniversalResult<>(UniversalResult.SUCCESS, "查询成功", univCampusMapper.getLastActByCampID(Integer.parseInt(map.get("campId").toString())));
    }

}
